﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MKS.model;
using System.Data.Common;

namespace MKS.DAL
{
    public  class GoodsSql
    {
        private DBHelper a = DBHelper.GetDBHelper();
        public List<GoodsInfo> fo(string cole)
        {
            List<GoodsInfo> list = new List<GoodsInfo>();
            string sql = "select * from GoodsInfo where GoodsCode like '%" + cole + "%'";
            DbDataReader dr = a.GetReader(sql);
            while (dr.Read())
            {
              
                GoodsInfo s = new GoodsInfo();
                if (dr["Company"] !=DBNull.Value )
                {
                  s.Company = Convert.ToInt32(dr["Company"]);
                }
                
                s.GoodsCode = dr["GoodsCode"].ToString();
                s.GoodsState = Convert.ToInt32(dr["GoodsState"]);
                s.OriginPrice = Convert.ToDouble(dr["OriginPrice"]);
                s.SalePrice = Convert.ToDouble(dr["SalePrice"]);
                if (dr["Stock"] !=DBNull.Value )
                {
                   s.Stock = Convert.ToInt32(dr["Stock"]);
                }
                s.Unit = dr["Unit"].ToString();
                if(dr["Supplier"] !=DBNull.Value)
                {
                  s.Supplier = Convert.ToInt32(dr["Supplier"]);
                }
                
                s.GoodsName = dr["GoodsName"].ToString();
                list.Add(s);
            }
            dr.Close();
            a.Close();
            return list;
        }
    }
}
